<?php

/**
 * contains all ajax request and returns json encoded results
 * @author fkauschmann
 *
 */
class AjaxController extends Zend_Controller_Action
{
	/**
	 * returns inventoryItemDesc based on inventoryItem
	 */
	public function getitemdescAction()
	{
		$request = $this->getRequest();
		$item = $request->getParam('inventoryItem');
		$itemMapper = new Application_Model_DbTable_inventoryItem();
		
		$sql = $itemMapper->select()
								->from('bis.tbl_inventoryItem', null)
								->columns('inventoryItemDesc')
								->where('inventoryItem=\''.$item.'\'');
		
		$result = $sql->query()->fetch();
		
		$this->_helper->json($result);
	}
	
	/**
	 * returns salesrep based on customer party number
	 */
	public function getsalesrepbycustomerAction()
	{
		$request = $this->getRequest();
		 
		$salesrepMapper = new Application_Model_SalesrepMapper();
		 
		$salesrep = $salesrepMapper->getSalesRepByPartyNumber($request->getParam('partynumber'));
	
		$this->_helper->json($salesrep);
	}
	
	/**
	 * returns outletname based on sapcode
	 */
	public function getoutletbysapcodeAction()
	{
		$request = $this->getRequest();
	
		$customerMapper = new Application_Model_CustomerMapper();
	
		$sapCode = $customerMapper->getOutletBySapcode($request->getParam('sapcode'));
	
		$this->_helper->json($sapCode);
	}
	
}